package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.NoticeService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.NoticeDto;
import com.huilian.iotbox.data.po.Notice;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/10/9 16:17
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController extends UserInfoController {
    @Autowired
    private NoticeService noticeService;

    @GetMapping("/findNoticeListByUserId")
    public ServerResponse findNoticeListByUserId(HttpServletRequest request, NoticeDto noticeDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return ServerResponse.createBySuccess(noticeService.findNoticeListByUserId(userInfo, noticeDto));
    }

    /**
     * 查询未读取的消息次数
     */
    @GetMapping("/findDidNotReadCount")
    public ServerResponse findDidNotReadCount(HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return ServerResponse.createBySuccess(noticeService.findDidNotReadCount(userInfo));
    }

    /**
     * 查询未读取的消息
     */
    @GetMapping("/findNotice")
    public ServerResponse findDidNotRead(HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return ServerResponse.createBySuccess(noticeService.findNotice(userInfo));
    }

    @PutMapping("/changeNormal")
    public ServerResponse changeNormal(HttpServletRequest request, @RequestBody Notice notice) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        return noticeService.changeNormal(notice);
    }
}
